/**
 * DiggApiNet - Digg API .NET Wrapper
 * 
 * Author: Sean Hickey
 * Link: http://www.headzoo.com/digg_api_net
 * License: GPL v2 ( http://www.gnu.org/licenses/gpl.txt )
 */
using System;
using System.Collections;
using System.Text;
using System.Web;

namespace DiggApiNet
{
    public partial class DiggApi
    {
        public class ListStories : DiggApi
        {
            private const string get_all                    = "http://services.digg.com/stories/{0}";
            private const string get_popular                = "http://services.digg.com/stories/popular/{0}";
            private const string get_upcoming               = "http://services.digg.com/stories/upcoming/{0}";
            private const string get_container              = "http://services.digg.com/stories/container/{0}/{1}";
            private const string get_container_popular      = "http://services.digg.com/stories/container/{0}/popular/{1}";
            private const string get_container_upcoming     = "http://services.digg.com/stories/container/{0}/upcoming/{1}";
            private const string get_topic                  = "http://services.digg.com/stories/topic/{0}/{1}";
            private const string get_topic_popular          = "http://services.digg.com/stories/topic/{0}/popular/{1}";
            private const string get_topic_upcoming         = "http://services.digg.com/stories/topic/{0}/upcoming/{1}";
            private const string get_by_id                  = "http://services.digg.com/story/{0}/{1}";
            private const string get_by_ids                 = "http://services.digg.com/stories/{0}/{1}";
            private const string get_by_title               = "http://services.digg.com/story/{0}/{1}";
            private const string get_by_user                = "http://services.digg.com/user/{0}/submissions/{1}";

            public DiggStories GetAll()
            {
                return GetAll(new Hashtable());
            }
            public DiggStories GetAll(Hashtable args)
            {
                string uri = String.Format(get_all, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStories GetPopular()
            {
                return GetPopular(new Hashtable());
            }
            public DiggStories GetPopular(Hashtable args)
            {
                string uri = String.Format(get_popular, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStories GetUpcoming()
            {
                return GetUpcoming(new Hashtable());
            }
            public DiggStories GetUpcoming(Hashtable args)
            {
                string uri = String.Format(get_upcoming, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStories GetByContainer(string container_name)
            {
                return GetByContainer(container_name, new Hashtable());
            }
            public DiggStories GetByContainer(string container_name, Hashtable args)
            {
                container_name = HttpUtility.UrlEncode(container_name);
                string uri = String.Format(get_container, container_name, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStories GetByContainerPopular(string container_name)
            {
                return GetByContainerPopular(container_name, new Hashtable());
            }
            public DiggStories GetByContainerPopular(string container_name, Hashtable args)
            {
                container_name = HttpUtility.UrlEncode(container_name);
                string uri = String.Format(get_container_popular, container_name, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStories GetByContainerUpcoming(string container_name)
            {
                return GetByContainerUpcoming(container_name, new Hashtable());
            }
            public DiggStories GetByContainerUpcoming(string container_name, Hashtable args)
            {
                container_name = HttpUtility.UrlEncode(container_name);
                string uri = String.Format(get_container_upcoming, container_name, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStories GetByTopic(string topic_name)
            {
                return GetByTopic(topic_name, new Hashtable());
            }
            public DiggStories GetByTopic(string topic_name, Hashtable args)
            {
                topic_name = HttpUtility.UrlEncode(topic_name);
                string uri = String.Format(get_topic, topic_name, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStories GetByTopicPopular(string topic_name)
            {
                return GetByTopicPopular(topic_name, new Hashtable());
            }
            public DiggStories GetByTopicPopular(string topic_name, Hashtable args)
            {
                topic_name = HttpUtility.UrlEncode(topic_name);
                string uri = String.Format(get_topic_popular, topic_name, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStories GetByTopicUpcoming(string topic_name)
            {
                return GetByTopicUpcoming(topic_name, new Hashtable());
            }
            public DiggStories GetByTopicUpcoming(string topic_name, Hashtable args)
            {
                topic_name = HttpUtility.UrlEncode(topic_name);
                string uri = String.Format(get_topic_upcoming, topic_name, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStory GetById(long id)
            {
                return GetById(id, new Hashtable());
            }
            public DiggStory GetById(long id, Hashtable args)
            {
                string uri = String.Format(get_by_id, id, HttpBuildUrl(args));
                return new DiggStory(Request(uri));
            }

            public DiggStories GetByIds(long[] ids)
            {
                return GetByIds(ids, new Hashtable());
            }
            public DiggStories GetByIds(long[] ids, Hashtable args)
            {
                string[] comb_array = new string[ids.Length];
                int i = 0;
                for (i = 0; i < ids.Length; i++) {
                    comb_array[i] = ids[i].ToString();
                }
                string comb_ids = HttpUtility.UrlEncode(String.Join(",", comb_array));
                string uri = String.Format(get_by_ids, comb_ids, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }

            public DiggStory GetByTitle(string title)
            {
                return GetByTitle(title, new Hashtable());
            }
            public DiggStory GetByTitle(string title, Hashtable args)
            {
                title = HttpUtility.UrlEncode(title);
                string uri = String.Format(get_by_title, title, HttpBuildUrl(args));
                return new DiggStory(Request(uri));
            }

            public DiggStories GetByUser(string user)
            {
                return GetByUser(user, new Hashtable());
            }
            public DiggStories GetByUser(string user, Hashtable args)
            {
                user = HttpUtility.UrlEncode(user);
                string uri = String.Format(get_by_user, user, HttpBuildUrl(args));
                return new DiggStories(Request(uri));
            }
        }
    }
}
